﻿using University;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace UniversityTest
{
    [TestClass]
    public class CourseTest
    {
        [TestMethod]
        public void AddCourseTest()
        {
            string courseName = "High-quality Code";
            Course newCourse = new Course(courseName);
            Assert.AreEqual(courseName, newCourse.Name);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException), "Name can not be null!")]
        public void AddCourseNoNameTest()
        {
            string name = null;
            Course target = new Course(name);
        }
        
        [TestMethod]
        public void AddStudentTest()
        {
            Course target = new Course("High-quality Code");
            Student student = new Student("Gosho", 11111);
            target.AddStudent(student);
            Student actualStudent = target.Students[0];
            Assert.AreEqual(student, actualStudent);
        }

        [TestMethod]
        [ExpectedException(typeof(Exception), "The course is already full and no more students can be added!")]
        public void AddStudentOverTheLimitTest()
        {
            Course target = new Course("High-quality Code");
            for (int i = 0; i < 30; i++)
            {
                Student student = new Student("Pesho", 10000 + i);
                target.AddStudent(student);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The course already contains a student with fn: 12345!")]
        public void AddStudentWithSameFNTest()
        {
            Course target = new Course("High-quality Code");
            Student student = new Student("Sasho", 11111);
            target.AddStudent(student);
            target.AddStudent(student);
        }

        [TestMethod]
        public void RemoveStudentByFNTest()
        {
            Course target = new Course("High-quality Code");
            Student student = new Student("Gosho", 11111);
            target.AddStudent(student);
            int fn = student.FN;
            target.RemoveStudentByFN(fn);
            int expectedStudentsCount = 0;
            int actualStudentsCount = target.Students.Count;
            Assert.AreEqual(expectedStudentsCount, actualStudentsCount);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), 
            "The student with fn: 12345 is not attending this course and can not be removed!")]
        public void RemoveStudentByNotExistingFNTest()
        {
            Course target = new Course("High-quality Code");
            Student student = new Student("Todor", 11111);
            target.AddStudent(student);
            int fn = 12345;
            target.RemoveStudentByFN(fn);
        }
    }
}
